/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProductOverview.java
 *
 * Created on 28-nov-2011, 12:22:25
 */
package view;

import java.util.List;
import java.util.Locale.Category;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import main.WinkelApplication;
import model.Product;

/**
 *
 * @author Bryan
 */
public class StockOverview extends javax.swing.JPanel {

    /** Creates new form ProductOverview */
    public StockOverview() {
        initComponents();
        
        List<Product> products = WinkelApplication.getQueryManager().getMinProducts();
        DefaultTableModel modelProd = (DefaultTableModel) this.tblProducts.getModel();
        
        List<model.Category> categories = WinkelApplication.getQueryManager().getCategories();
        
        for(Product product: products) {
            modelProd.addRow(new Object[] {new Integer(product.getProductId()),
            product.getCategory(),
            product.getName(),
            product.getPriceFormatted(),
            product.getDescription(),
            product.getStock(),
            product.getMinStock(), 
            (product.getMinStock() - product.getStock())});
        }
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollProducts = new javax.swing.JScrollPane();
        tblProducts = new javax.swing.JTable();
        btnBack = new javax.swing.JButton();
        LeverancierButton = new javax.swing.JButton();
        Bestelbutton = new javax.swing.JButton();

        setMaximumSize(new java.awt.Dimension(1000, 700));
        setMinimumSize(new java.awt.Dimension(1000, 700));

        tblProducts.setAutoCreateRowSorter(true);
        tblProducts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Product id", "Categorie", "Naam", "Prijs", "Omschrijving", "Voorraad", "Min Voorraad", "Bestellen"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblProducts.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        tblProducts.setName("tblProducts"); // NOI18N
        tblProducts.getTableHeader().setReorderingAllowed(false);
        scrollProducts.setViewportView(tblProducts);
        tblProducts.getColumnModel().getColumn(0).setResizable(false);
        tblProducts.getColumnModel().getColumn(0).setPreferredWidth(30);
        tblProducts.getColumnModel().getColumn(1).setResizable(false);
        tblProducts.getColumnModel().getColumn(3).setPreferredWidth(25);
        tblProducts.getColumnModel().getColumn(5).setPreferredWidth(20);
        tblProducts.getColumnModel().getColumn(6).setPreferredWidth(20);
        tblProducts.getColumnModel().getColumn(7).setPreferredWidth(20);

        btnBack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/imgBack.png"))); // NOI18N
        btnBack.setText("Terug");
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });

        LeverancierButton.setText("Leveranciers");
        LeverancierButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LeverancierButtonActionPerformed(evt);
            }
        });

        Bestelbutton.setText("Bestellen");
        Bestelbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BestelbuttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(btnBack)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(Bestelbutton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(LeverancierButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(scrollProducts, javax.swing.GroupLayout.PREFERRED_SIZE, 968, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrollProducts, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnBack)
                    .addComponent(LeverancierButton)
                    .addComponent(Bestelbutton))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
    WinkelApplication.getInstance().showPanel(new MainMenu());
}//GEN-LAST:event_btnBackActionPerformed

private void LeverancierButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LeverancierButtonActionPerformed
    //todo here
}//GEN-LAST:event_LeverancierButtonActionPerformed

private void BestelbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BestelbuttonActionPerformed
    WinkelApplication.getInstance().showPanel(new OrderProduct(),205,454);
}//GEN-LAST:event_BestelbuttonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Bestelbutton;
    private javax.swing.JButton LeverancierButton;
    private javax.swing.JButton btnBack;
    private javax.swing.JScrollPane scrollProducts;
    private javax.swing.JTable tblProducts;
    // End of variables declaration//GEN-END:variables
}
